This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Oct 26, 2012, 3:09 PM
47 Posts
topic has been resolvedResolved

Problem with getdatabase and getview

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 8

I want to get all the values from the first column in another database on the same server.  What am I doing wrong?

 

var server = session.getCommonUserName(); // return the server name for server-side javascript
print ('server  is ' + server); // return --> server  is bibis

 
If I try to do a 'getDatabase', I get an error 
var dbname = session.getDatabase('', "tair1.nsf"); // Exception occurred calling method NotesSession.getDatabase(string, string) null
 
The following one is working 
var dbname = new Array(server, "tair1.nsf"); // return -->database is bibis,database is tair1.nsf 
print ('database is ' + dbname) ;
 
Next, I need to get the view, but I always receive an error :
 var vw = dbname.getView("(Mission by CATS recent)"); //Error calling method 'getView(string)' on an object of type 'Array [JavaScript Object]'
print('vw is ' + vw);
 
Finally, I want to get the first.  Of course, since I can't get the view, it is impossible to test the column number. 
 var column = view.getColumn(1);
Oct 26, 2012, 5:04 PM
298 Posts
here is your issue
  The following one is working  var dbname = new Array(server, "tair1.nsf"); // return -->database is bibis,database is tair1.nsf  print ('database is ' + dbname) ;   Now you have an array called dbname that has the two members in it, you can't use getView on this...like you did below In the getView method below you have to call that on a database object. So, you need the getDatabase method like: var otherDB = session.getDatabase(server, "tair1.nsf"); Next, I need to get the view, but I always receive an error :  var vw = dbname.getView("(Mission by CATS recent)"); //Error calling method 'getView(string)' on an object of type 'Array [JavaScript Object]' print('vw is ' + vw); Howard
Oct 27, 2012, 1:24 PM
47 Posts
Re: Problem with getdatabase and getview
Hi Howard,
 
I did what you wrote but I still get an error: 
The runtime has encountered an unexpected error.

Error source

Page Name:/DocExpense.xsp

Exception

Error while executing JavaScript computed expression
Script interpreter error, line=4, col=23: [TypeError] Exception occurred calling method NotesSession.getDatabase(string, string) null

JavaScript code

   1: var server = session.getCommonUserName(); 
   2: print ('server  is ' + server); // return the name of the server 
   3: 
   4: var otherDB = session.getDatabase(server, "tair1.nsf"); 
   5: print ('database is ' + otherDB) ;
   6: 
   7: var vw = otherDB.getView("(Mission by CATS recent)");
   8: print('vw is ' + vw);
Oct 27, 2012, 9:31 PM
298 Posts
Do you have proper rights to the other database?
Check your security access, remember, the code is running as the web user. Also, try "" for the server name. By the way, Line 5 is wrong, you can't "print" otherDB, it is a database object, try getTitle() or something... Howard
Oct 29, 2012, 7:35 AM
14 Posts
Re: Problem with getdatabase and getview
Danyele,
 
I would not recommend  using getCommonUserName. It returns the server when used on a server side script but it's used to return the user running the script, so use session.getServerName() to retrieve the server in a reliable way.
 
For the error message, is the database you try to open on the same server as the database you run this code ? If yes, you need to check if the server you run this code can access the other server. When you use loutsscript, you have to setup the calling server as a trusted server to allow access using serverside code, so it's probably the same for SSJS code in xpages.
  
You might look for trusted servers on the admin help to have details about this.
 
Hope this helps. 

Renaud 
Oct 29, 2012, 12:04 PM
47 Posts
Re: Problem with getdatabase and getview

Thank you both for the tips on getTitle() and getServerName(), I did not think about that.

I tried "" for the server name, but it did not change anything.

Also, the database is on the same server which is a test server. The line to get the server name is working perfectly and returning:

10/29/2012 06:47:50 AM HTTP JVM: server is CN=bibis/O=yti

 
I have access to the database and the view from the web with "http://servername/databasename/(Mission%20by%20CATS%20recent)?OpenView"  and I can modify everything, so what am I missing ?
Nov 1, 2012, 11:27 AM
47 Posts
Re: Problem with getdatabase and getview
I came up with a solution but it is not complete.
 

var server = session.getServerName();

try {

var tai:NotesDatabase = session.getDatabase("", "tair1.nsf");

if(tai.isOpen()){

var vw:NotesView = tai.getView("(Mission by CATS recent)");

var count:int = vw.getColumnCount();

var allentries = vw.getAllEntries();

print('nb docs ' + allentries.getCount().toFixed());

var nav:NotesViewNavigator = vw.createViewNav();

var entry:NotesViewEntry = nav.getFirst();

var result = "\n";

while (entry != null ){

// have to accumulate the values here - first column is CATS and second (last) is Exercise 

// I need to see the 2 columns in my combobox (in the form it is a dialog list "Use view dialog for choices" that will keep column 1 (CATS)

result += entry.getColumnValues().firstElement().toString()+ "\t" + entry.getColumnValues().lastElement().toString() + "\n";

print (result); // ok returns my 2 columns

// go to next and recycle the actual one

var tmpentry:NotesViewEntry = nav.getNext();

entry.recycle();

entry = tmpentry;

}

// have to put the return here

return result; // doesn't return anything

}

} catch(e) {} // proceed if there is an error

 
The following doesn't work:

// Help documentation says: A column number where columns are numbered left to right starting with 0.

//var cats:java.util.Vector = vw.getColumnValues(0); // like if there were nothing in this column

//var cats = entry.getColumnValues(1); //  this work but give me the second column Exercise

  
Nov 1, 2012, 1:17 PM
298 Posts
getColumnValues does not use a parameter
I am not sure what help you were looking at but getColumnValues on a view Entry returns a Vector. Use elementAt() to get to each column, the first column would be .elementAt(0). Where is your code located? You are returning one big string with the results of the view. If you do a print(result) after your while loop does it output a big string to the console? Howard
Nov 2, 2012, 10:58 AM
47 Posts
Re: Problem with getdatabase and getview
Hi Howard,
 
I already tried with elementAt() but I did not get anything.  So yesterday night I went on a different direction and I used a Value Picker.  In my view I created another column which contains the 2 columns separated by some "-" and an Edit box for the choosen value. Now, everything is working

xe:valuePicker id="valuePicker1"

   pickerText="CATS/Work Order Number" for="inputText1"

   listWidth="400" dialogTitle="Work Order Number">

   <xe:this.dataProvider>

       <xe:dominoViewValuePicker

             labelColumn="$3">

             <xe:this.databaseName><![CDATA[#{javascript:session.getDatabase("", "tair1.nsf");}]]></xe:this.databaseName>

             <xe:this.viewName><![CDATA[#{javascript:"(Mission by CATS recent)";}]]></xe:this.viewName>

       </xe:dominoViewValuePicker>

   </xe:this.dataProvider>

</xe:valuePicker

Thank you all for your help


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal